package minio;

import io.minio.ListObjectsArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import io.minio.messages.Bucket;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * All rights Reserved, Designed By www.tusdao.com
 *
 * @version V1.0
 * @Title: ListBuckets
 * @Package myTest
 * @Description: TODO(一句话描述类是干嘛的)
 * @author: tusxxw
 * @date: 2020/9/15
 * @Copyright: 2020 www.tbs.com Inc. All rights reserved.
 * <p>
 * 注意：本内容仅限于TBS项目组内部传阅，禁止外泄以及用于其他的商业目的
 */
public class ListBuckets {
    /** MinioClient.listBuckets() example. */
    public static void main(String[] args)
            throws IOException, NoSuchAlgorithmException, InvalidKeyException {
        try {
            /* play.min.io for test and development. */
            MinioClient minioClient = new MinioClient("http://39.105.184.167:8900/", "admin", "Tustbs515");

            /* Amazon S3: */
            // MinioClient minioClient =
            //     MinioClient.builder()
            //         .endpoint("https://s3.amazonaws.com")
            //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
            //         .build();

            // List buckets we have atleast read access.
            List<Bucket> bucketList = minioClient.listBuckets();

            for (Bucket bucket : bucketList) {
                System.out.println(bucket.creationDate() + ", " + bucket.name());
            }

        } catch (MinioException e) {
            System.out.println("Error occurred: " + e);
        }
    }
}
